unit uImportParticipantForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ExtCtrls, StdCtrls;

type
  TImportParticipantForm = class(TForm)
    lvMeeting: TListView;
    Panel1: TPanel;
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure lvMeetingSelectItem(Sender: TObject; Item: TListItem;
      Selected: Boolean);
    procedure FormShow(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
  private
    { Private declarations }
    FMeetings: TStringList;
  public
    { Public declarations }
    Participants: string;
  end;

implementation

uses
  uGlobal;

{$R *.dfm}

procedure TImportParticipantForm.Edit1Change(Sender: TObject);
var
  i: Integer;
begin
  lvMeeting.Items.Clear;
  for i := 0 to FMeetings.Count - 1 do
  begin
    if Pos(Edit1.Text, FMeetings[i])>0 then
    begin
      with lvMeeting.Items.Add do
      begin
        Caption := FMeetings[i];
        Data := FMeetings.Objects[i];
      end;
    end;
  end;
end;

procedure TImportParticipantForm.FormCreate(Sender: TObject);
begin
  FMeetings := TStringList.Create;
  if ExecuteQuery('SELECT * FROM tbMeeting')>=0 then
  while not G_Query.Eof do
  begin
    with lvMeeting.Items.Add do
    begin
      Caption := G_Query.FieldByName('MeetingName').AsString;
      Data := Pointer(G_Query.FieldByName('idx').AsInteger);
      FMeetings.AddObject(Caption, Data);
    end;
    G_Query.Next;
  end;
end;

procedure TImportParticipantForm.FormDestroy(Sender: TObject);
begin
  FMeetings.Free;
end;

procedure TImportParticipantForm.FormShow(Sender: TObject);
begin
  Edit1.SetFocus;
end;

procedure TImportParticipantForm.lvMeetingSelectItem(Sender: TObject;
  Item: TListItem; Selected: Boolean);
begin
  if ExecuteQuery(Format('SELECT * FROM tbMeeting WHERE idx=%d', [Integer(Item.Data)]))>0 then
  begin
    Participants := G_Query.FieldByName('Participants').AsString;
    ModalResult := mrOk;
  end;
end;

end.
